package study.stream.flatMap的练习;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author 金贵权
 * @Date 2023/6/12 15:06
 **/
public class flatMapTest01 {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1,2,3,4,5);
        List<Integer> collect = list.stream().map(x -> x * x).collect(Collectors.toList());
        System.out.println(collect);
        List<Integer> integers = Arrays.asList(1, 2, 3);
        List<Integer> integers1 = Arrays.asList(3, 4);
        List<int[]> collect1 = integers.stream().flatMap(x -> integers1.stream().map(y -> new int[]{x, y})).collect(Collectors.toList());

        List<int[]> collect2 = integers.stream().flatMap(x -> integers1.stream().filter(y -> (y + x) % 3 == 0).map(y -> new int[]{x, y})).collect(Collectors.toList());
        for (int[] ints : collect2) {
            System.out.println(ints);
            for (int anInt : ints) {
                System.out.println(anInt);
            }
        }
    }
}
